<?php
/**
 * Created by JetBrains PhpStorm.
 * User: valera
 * Date: 4/14/11
 * Time: 9:16 AM
 * To change this template use File | Settings | File Templates.
 */

class AuthorController extends Core_Controller_Action
{
    protected $_style = array('/styles/catalog.css', '/styles/other.css');

    protected $_filters = array("new" => Api_Select_Product::FILTER_NEW, "disc" => Api_Select_Product::FILTER_DISCOUNT, "aval" => Api_Select_Product::FILTER_AVAL);

    protected $_sorts = array("code" => Api_Select_Product::SORT_CODE, "name" => Api_Select_Product::SORT_NAME, "price" => Api_Select_Product::SORT_PRICE);

    protected function _initParams()
    {
        $filter = $this->view->filter = $this->_getParam('filter', Api_Select_Product::FILTER_ALL);
        $sort = $this->view->sort = $this->_getParam('sort', Api_Select_Product::SORT_PRICE);
        $is_asc = $this->view->is_asc = $this->_getParam('is_asc', true);
        return array($filter, $sort, $is_asc);
    }

    public function indexAction()
    {
        $this->view->headLink()->appendStylesheet('/styles/authors.css');
        $ProfessionId = $this->_getParam('prof', 0);
//var_dump($this->_api->Authors->getByProfession((int)$ProfessionId)->id); die();
//        $Navigation = new Zend_Navigation();
//        $Navigation->addPage(
//            $Page = Zend_Navigation_Page_Mvc::factory(
//                array(
//                     'label' => 'Всі майстри',
//                     'controller' => 'author',
//                     'action' => 'index',
//                     'params' => array('prof' => 0)
//                )
//            )
//        );
//        if ($ProfessionId === 0) $Page->setActive(TRUE);
//        foreach ($this->_api->Profession->getAll() as $Profession) {
//            $author->addPage(new Zend_Navigation_Page_Uri ($Profession->NavigationPage()));
//        }

        $authorId = $this->view->Authors = $this->_api->Authors->getByProfession((int)$ProfessionId);
        $nav = Zend_Registry::get('Zend_Navigation');
        $author = $nav->findOneBy ( 'id', 'author' );
        $author->setActive(true);

        $author->findOneBy('id', $ProfessionId)->setActive(true);  
        $this->view->FilterMenu = $author;
        $this->view->subId = $ProfessionId;
    }

    public function detailsAction()
    {
        $AuthorId = $this->_getParam('id', 0);
        $authorId = $this->view->Authors = $this->_api->Authors->getByProfession((int)0);
        $nav = Zend_Registry::get('Zend_Navigation');
        $author = $nav->findOneBy ( 'id', 'author' );
        $author->setActive(true);

        $author->findOneBy('id', 0)->setActive(true);  
        $this->view->FilterMenu = $author;
        $this->view->Author = $this->_api->Authors->getOne($AuthorId);
    }

    public function worksAction()
    {
        $this->view->headLink()->appendStylesheet("/styles/productList.css");

        list ($filter, $sort, $is_asc) = $this->_initParams();

        $Author = $this -> _api -> Authors -> getOne( (int) $this -> _getParam('author') );
        $this -> view -> isAuthorPage = true;
        $this->view->products = $this -> _api -> Product -> FetchByAuthor( $Author->id, $filter, $sort, $is_asc );
        $this->view->productListTitle = "Всі роботи {$Author -> Name()}";
    }
}